// 两数相加
var twoSum = function (nums, target) {
  for (let i = 0; i < nums.length - 1; i++) {
    for (let j = i + 1; j < nums.length; j++) {
      if (nums[i] + nums[j] === target) {
        return [i, j]
      }
    }
  }
  return []
}

var twoSum = function (nums, target) {
  const map = new Map()
  for (let i = 0; i < nums.length; i++) {
    map.set(nums[i], i)
  }
  for (let i = 0; i < nums.length; i++) {
    let cha = target - nums[i]
    if (map.has(cha) && map.get(cha) !== i) {
      return [i, map.get(cha)]
    }
  }
  return []
}

// 三数相加

// 无重复最长子串
var lengthOfLongestSubstring = function (s) {
  const occ = new Set()
  let right = -1
  let ans = 0
  for (let i = 0; i < s.length; i++) {
    if (i !== 0) {
      occ.delete(s[i - 1])
    }
    while (right + 1 < s.length && !occ.has(s[right + 1])) {
      occ.add(s[right + 1])
      right++
    }
    ans = Math.max(ans, right + 1 - i)
  }
  return ans
}

// 火车进出站

// 最大公约数
var gcd = function (min, max) {
  return max === 0 ? min : gcd(max, min % max)
}
var solution = function (nums) {
  let min = Infinity
  let max = -Infinity
  for (let num of nums) {
    if (num > max) max = num
    if (num < min) min = num
  }

  return gcd(min, max)
}

// 最大公倍数

// 求众数

// 四则运算
